package cn.wen.forum.common.util;

import java.util.List;
import java.util.Map;

/**
 * @ClassName StringUtils
 * @Author By wen
 * @Description
 * @Date 2023/8/8 9:08
 * @Version 1.0
 */
public class StringUtils {


    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }

    public static boolean isNotEmpty(String str) {
        return !StringUtils.isEmpty(str);
    }

    public static boolean isBlank(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if ((Character.isWhitespace(str.charAt(i)) == false)) {
                return false;
            }
        }
        return true;
    }

    public static boolean isNotBlank(String str) {
        return !StringUtils.isBlank(str);
    }

    public static boolean equals(String str1, String str2) {
        return str1 == null ? str2 == null : str1.equals(str2);
    }

    public static boolean isNull(Object object) {
        if(null == object){
            return true;
        }
        if(object instanceof List){
            if(((List) object).size() == 0){
                return true;
            }
        }
        if(object instanceof Map){
            if(((Map) object).size() == 0){
                return true;
            }
        }
        return false;
    }

    public static boolean isNotNull(Object object) {
        return !isNull(object);
    }

    /**
     * 将浏览量做处理，转为99+、999+ 的形式
     * @param pageView
     * @return
     */
    public static String handlerPageViewCount(String pageView) {
        Integer count = Integer.parseInt(pageView);
        if(count <= 99){
            return String.valueOf(count);
        }
        if(count <= 999){
            return "99+";
        }
        if(count <= 9999){
            return "999+";
        }
        return String.valueOf(count);
    }
}
